/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>网站全局基本设置，商城及其他模块相关内容在其各自栏目设置项内进行操作。</li>
          <li>该页面的所有默认图标logo在"网站根目录/public/static/images/logo"目录下, 如果需要重新设计图标可参考默认图</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>

    <el-form ref="form" :model="form" label-width="200px" label-position="right">
		<el-form-item label="接口域名">
		  <el-input v-model="form.host" size="mini"></el-input>
		  <p class="notic">示例:https://j.tpsns.com（注:必须是https://开头的域名，用于接受微信小程序等支付通知）</p>
		</el-form-item>
      <el-form-item label="网站备案号">
        <el-input v-model="form.record_no" size="mini"></el-input>
        <p class="notic">网站备案号，将显示在前台底部欢迎信息等位置</p>
      </el-form-item>
      <el-form-item label="网站名称">
        <el-input v-model="form.store_name" size="mini"></el-input>
        <p class="notic">网站名称，将显示在前台顶部欢迎信息等位置</p>
      </el-form-item>
      <el-form-item label="公司名称">
        <el-input v-model="form.company_name" size="mini"></el-input>
        <p class="notic">公司名称:将显示在管理员后台欢迎页面</p>
      </el-form-item>
      <el-form-item label="网站Logo">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=logo'"
          :show-file-list="false"
          :on-success="handleStoreLogo"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.store_logo"
            :src="form.store_logo"
            style="width:230px; height:58px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <p class="notic">默认网站首页LOGO,通用头部显示，最佳显示尺寸为230*58像素</p>
      </el-form-item>
      <el-form-item label="网站用户中心Logo">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=logo'"
          :show-file-list="false"
          :on-success="handleStoreUserLogo"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.store_user_logo"
            :src="form.store_user_logo"
            style="width:230px; height:58px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <p class="notic">默认用户中心网站LOGO,用户中心通用头部显示，最佳显示尺寸为230*58像素</p>
      </el-form-item>
      <el-form-item label="网站标题图标">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=logo'"
          :show-file-list="false"
          :on-success="handleStoreIco"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.store_ico"
            :src="form.store_ico"
            style="width:48px; height:48px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <p class="notic">网站标题图标LOGO,最佳显示尺寸为48*48像素</p>
      </el-form-item>
      <el-form-item label="网站标题">
        <el-input v-model="form.store_title" size="mini"></el-input>
        <p class="notic">网站标题，将显示在前台顶部欢迎信息等位置</p>
      </el-form-item>
      <el-form-item label="网站描述">
        <el-input v-model="form.store_desc" size="mini"></el-input>
        <p class="notic">网站描述，将显示在前台顶部欢迎信息等位置</p>
      </el-form-item>
      <el-form-item label="网站关键字">
        <el-input v-model="form.store_keyword" size="mini"></el-input>
        <p class="notic">网站关键字，便于SEO</p>
      </el-form-item>
      <el-form-item label="商家登录页Logo">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=logo'"
          :show-file-list="false"
          :on-success="handleSellerLoginLogo"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.seller_login_logo"
            :src="form.seller_login_logo"
            style="width:163px; height:26px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <p class="notic">商家登录页LOGO,最佳显示尺寸为163*26像素</p>
      </el-form-item>
      <el-form-item label="平台管理员登录页Logo">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=logo'"
          :show-file-list="false"
          :on-success="handleAdminLoginLogo"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.admin_login_logo"
            :src="form.admin_login_logo"
            style="width:220px; height:82px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <p class="notic">平台管理员登录页LOGO,最佳显示尺寸为220*82像素</p>
      </el-form-item>
      <el-form-item label="平台后台顶部Logo">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=logo'"
          :show-file-list="false"
          :on-success="handleAdminHomeLogo"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.admin_home_logo"
            :src="form.admin_home_logo"
            style="width:148px; height:28px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <p class="notic">平台后台顶部LOGO,最佳显示尺寸为148*28像素</p>
      </el-form-item>
      <el-form-item label="手机端首页Logo">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=logo'"
          :show-file-list="false"
          :on-success="handleWapHomeLogo"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.wap_home_logo"
            :src="form.wap_home_logo"
            style="width:48px; height:48px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <p class="notic">手机端首页搜索框LOGO,最佳显示尺寸为48*48像素</p>
      </el-form-item>
      <el-form-item label="手机端登录页Logo">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=logo'"
          :show-file-list="false"
          :on-success="handleWapLoginLogo"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.wap_login_logo"
            :src="form.wap_login_logo"
            style="width:312px; height:92px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <p class="notic">手机端登录页LOGO,最佳显示尺寸为312*92像素</p>
      </el-form-item>
      <el-form-item label="公众号二维码">
        <el-upload
          class="avatar-uploader"
          :action="apiHead + '/mall/upload?type=logo'"
          :show-file-list="false"
          :on-success="handleWeiXinQRCode"
          :before-upload="beforeAvatarUpload"
        >
          <el-image
            v-if="form.weixin_qrcode"
            :src="form.weixin_qrcode"
            style="width:90px; height:90px; display:block;"
          ></el-image>
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <p class="notic">pc端公共底部官方微信二维码,最佳显示尺寸为90*90像素</p>
      </el-form-item>
      <el-form-item label="联系人">
        <el-input v-model="form.contact" size="mini"></el-input>
        <p class="notic">联系人</p>
      </el-form-item>
      <el-form-item label="联系电话">
        <el-input v-model="form.phone" size="mini"></el-input>
        <p class="notic">联系电话</p>
      </el-form-item>
      <el-form-item label="具体地址">
        <el-input v-model="form.address" size="mini"></el-input>
        <p class="notic">具体地址</p>
      </el-form-item>
      <el-form-item label="平台客服QQ1">
        <el-input v-model="form.qq" size="mini"></el-input>
        <p class="notic">商家中心右下侧显示，方便商家遇到问题时咨询</p>
      </el-form-item>
      <el-form-item label="平台客服QQ2">
        <el-input v-model="form.qq2" size="mini"></el-input>
        <p class="notic">商家中心右下侧显示，方便商家遇到问题时咨询</p>
      </el-form-item>
      <el-form-item label="平台客服QQ3">
        <el-input v-model="form.qq3" size="mini"></el-input>
        <p class="notic">商家中心右下侧显示，方便商家遇到问题时咨询</p>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" :loading="subLoading">确认提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getConfigs, updateConfigs } from "@/utils/api";
export default {
  data() {
    return {
      form: {},
      subLoading: false
    };
  },
  created() {
    this.getConfigs();
  },
  methods: {
    getConfigs() {
      var that = this;
      getConfigs({ inc_type: "shop_info" }).then(function(res) {
        that.form = res.shop_info;
      });
    },
    onSubmit() {
      var that = this;
      that.subLoading = true;
      updateConfigs("shop_info", that.form).then(function(res) {
        that.subLoading = false;
        if (res.status == 1) {
          that.$message.success("保存成功");
        } else {
          that.$message.error("保存失败,失败原因:" + res.msg);
        }
      });
    },
    handleStoreLogo(res) {
      this.form.store_logo = res.result;
    },
    handleStoreUserLogo(res) {
      this.form.store_user_logo = res.result;
    },
    handleStoreIco(res) {
      this.form.store_ico = res.result;
    },
    handleSellerLoginLogo(res) {
      this.form.seller_login_logo = res.result;
    },
    handleAdminLoginLogo(res) {
      this.form.admin_login_logo = res.result;
    },
    handleAdminHomeLogo(res) {
      this.form.admin_home_logo = res.result;
    },
    handleWapHomeLogo(res) {
      this.form.wap_home_logo = res.result;
    },
    handleWapLoginLogo(res) {
      this.form.wap_login_logo = res.result;
    },
    handleWeiXinQRCode(res) {
      this.form.weixin_qrcode = res.result;
    },
    beforeAvatarUpload(file) {
      const isPic =
        file.type === "image/gif" ||
        file.type === "image/jpg" ||
        file.type === "image/jpeg" ||
        file.type === "image/png";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isPic) {
        this.$message.error("上传图片只能是 JPG、JPEG、PNG、GIF 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传图片大小不能超过 2MB!");
      }
      return isPic && isLt2M;
    }
  }
};
</script>
<style scoped>
.avatar-uploader-icon {
  line-height: 100px;
}

>>> .el-input--mini .el-input__inner {
  width: 300px;
}
</style>
